// 
//  Deck.m
//  Test_CD_SL_2
//
//  Created by Timothy Costa on 9/18/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Deck.h"
#import "Card.h"

@implementation Deck 

@dynamic name;
@dynamic dateCreated;
@dynamic cards;

-(void)awakeFromInsert
{
	static int count = 1;
	self.name = [NSString stringWithFormat: @"New Deck %i",count++];
}

-(Card*)addNewCard
{
	Card * newCardObject = [NSEntityDescription
						   insertNewObjectForEntityForName:@"Card"
						   inManagedObjectContext:self.managedObjectContext];
	[self addCardsObject: newCardObject];
	[newCardObject addDecksObject:self];
	
	return newCardObject;
}

-(NSDictionary*)deckDictionary
{
	return [self dictionaryWithValuesForKeys:[[self class] deckKeys]];
}
-(void)setDeckDictionary: (NSDictionary*)aDictionary
{
	[self setValuesForKeysWithDictionary:aDictionary];
}

+(NSArray*)deckKeys
{
	static NSArray* deckKeys=nil;
	if (deckKeys==nil)
		deckKeys = [[NSArray alloc] initWithObjects:@"name",@"dateCreated",@"cards",nil];
	return deckKeys;		
}
+ (NSSet *)keyPathsForValuesAffectingDeckDictionary
{
	return [NSSet setWithArray:[[self class]deckKeys]];
}

@end
